﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;

namespace Сlassifier_Tool_For_OpenCV
{
    public partial class Form2 : Form
    {
        private readonly List<Item> _items;
        private readonly TextBox _file;
        public Form2(List<Item> items, TextBox file, string infile)
        {

            InitializeComponent();
            _file = file;
            _items = items;
            var min = 0;
            for (var index = 0; index < items.Count; index++)
            {
                var item = items[index];
                if (items[index].Value <= items[min].Value) min = index;
                listBox1.Items.Add(item.Index + " " + item.Value);
            }
            listBox1.SelectedIndex = min;
            if (infile != "")
            {
                Text = "Save ann " + infile;
                saveFileDialog3.FileName = Path.GetDirectoryName(infile)  +"\\"+
                                           Path.GetFileNameWithoutExtension(infile) + ".ann";
            }
            else
            {
                Text = "Save hog vector ";
            }
        }


        public Form2(List<Item> items, string infile)
        {

            InitializeComponent();
       
            _items = items;
            var min = 0;
            for (var index = 0; index < items.Count; index++)
            {
                var item = items[index];
                if (items[index].Value <= items[min].Value) min = index;
                listBox1.Items.Add(item.Index + " " + item.Value);
            }
            listBox1.SelectedIndex = min;
     
            saveFileDialog3.FileName = Path.GetDirectoryName(infile) + "\\" +
                                           Path.GetFileNameWithoutExtension(infile) + ".ann";
            Text = Path.GetFileName(infile);
        }
      

        private void button1_Click(object sender, EventArgs e)
        {
            if (saveFileDialog3.ShowDialog() == DialogResult.OK)
            {
                _file.Text = saveFileDialog3.FileName;
                _items[listBox1.SelectedIndex].Save(saveFileDialog3.FileName);
            }
        }
    }
}
